package com.qfedu.service.impl;

import com.qfedu.mapper.ItemMapper;
import com.qfedu.model.Item;
import com.qfedu.page.PageResult;
import com.qfedu.page.QueryPageBean;
import com.qfedu.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author LiJH
 * @date 2023-02-10
 */
@Service
public class ItemServiceImpl implements ItemService {
    @Autowired
    private ItemMapper itemMapper;
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {

        PageResult pageResult = new PageResult();
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        long count = itemMapper.count();
        pageResult.setTotal(count);
        List<Item> page = itemMapper.findPage((currentPage - 1) * pageSize, pageSize);
        pageResult.setRows(page);
        return pageResult;
    }

    @Override
    public int addItem(Item item) {
        item.setUpdatetime(new Date());
        return itemMapper.addItem(item);
    }

    @Override
    public Item findById(String iid) {
        return   itemMapper.findById(iid);
    }

    @Override
    public int editItem(Item item) {
        item.setUpdatetime(new Date());
        int i = itemMapper.editItem(item);
        return i;
    }


    @Override
    public int deleteByIid(String iid) {
        return itemMapper.deleteByIid(iid);
    }

    @Override
    public List<Item> findBySuid(String suid) {
        return  itemMapper.findBySuid(suid);

    }
}